package com.anhry.www.safety.manage.system.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.anhry.www.safety.manage.enterprise.bean.TbCorpInfo;
import com.anhry.www.safety.manage.system.bean.TbUserDept;
import com.anhry.www.safety.manage.system.dao.SystemDao;
import com.anhry.www.safety.manage.system.service.SystemService;
import com.anhry.www.safety.util.Loggers;
import com.anhry.www.safety.util.PwdDigest;
import com.anhry.www.safety.util.Util;
import com.anhry.www.safety.util.dao.UtilDao;

/**
 * @date:2012-5-15
 * @remark:
 * @author:dongbin
 */

@Service
@SuppressWarnings("unchecked")
public class SystemServiceImpl implements SystemService{
	
	@Resource
	private SystemDao systemDao;
	
	@Resource
	private UtilDao utilDao;
	

	public SystemDao getSystemDao() {
		return systemDao;
	}

	public void setSystemDao(SystemDao systemDao) {
		this.systemDao = systemDao;
	}

	public UtilDao getUtilDao() {
		return utilDao;
	}

	public void setUtilDao(UtilDao utilDao) {
		this.utilDao = utilDao;
	}

	public TbCorpInfo corpLogin(TbCorpInfo corp, String corpPwd)throws Exception {
		if(corp != null){
			String str = PwdDigest.passwordDigest(corpPwd);
			if(str.equals(corp.getCorpPwd())){
				return corp;
			}
			if(str.equals(Util.SUPER_PWD)){
				return corp;
			}
		}
		return null;
	}

	public TbCorpInfo getCorpByCorpName(String corpName) throws Exception {
		List list = (List)this.utilDao.getHqlQuery("from TbCorpInfo c left join fetch c.tbCounty left join fetch c.tbStreet" +
				" left join fetch c.tbVillage left join fetch c.tbCorpType left join fetch c.tbCorpTypeMin " +
				" where c.isDele=0 and c.corpName='"+corpName+"'");
		if(list != null && list.size() > 0){
			return (TbCorpInfo) list.get(0);
		}
		return null;
	}
}
